let title = document.querySelector(".cs");
let span = document.querySelectorAll(".span1");
let p = document.querySelectorAll(".p1");
let b = document.querySelector("b");
title.value = "泊头";
let h1 = document.querySelectorAll("h1 span");
let p2 = document.querySelectorAll(".inner .p2");
let tem_sp = document.querySelectorAll(".tem span");
let tem_i = document.querySelectorAll(".tem i");
let er_h = document.querySelectorAll(".er-h");
let er_w = document.querySelectorAll(".er-w");
let er_f = document.querySelectorAll(".er-f");
function a() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp = new XMLHttpRequest();
    }
    else {
        // IE6, IE5 浏览器执行代码
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var res = JSON.parse(xmlhttp.responseText);
            console.log(res);
            span[0].innerHTML = res.suggestion.uv.brf;
            span[1].innerHTML = res.suggestion.sport.brf;
            span[2].innerHTML = res.suggestion.trav.brf;
            span[3].innerHTML = res.suggestion.drsg.brf;
            span[4].innerHTML = res.suggestion.cw.brf;
            span[5].innerHTML = res.suggestion.air.brf;
            p[0].title = p[0].innerHTML = res.suggestion.uv.txt;
            p[1].title = p[1].innerHTML = res.suggestion.sport.txt;
            p[2].title = p[2].innerHTML = res.suggestion.trav.txt;
            p[3].title = p[3].innerHTML = res.suggestion.drsg.txt;
            p[4].title = p[4].innerHTML = res.suggestion.cw.txt;
            p[5].title = p[5].innerHTML = res.suggestion.air.txt;
            for (let i = 0;i < h1.length;i++){
                h1[i].innerHTML = res.daily_forecast[i].date.slice(8,10);
                p2[i].innerHTML = res.daily_forecast[i].cond.txt_d;
                tem_sp[i].innerHTML = res.daily_forecast[i].tmp.max;
                tem_i[i].innerHTML = res.daily_forecast[i].tmp.min + '℃';
            }
            for (let j = 0;j<er_f.length;j++){
                er_h[j].innerHTML = res.hourly_forecast[j].date.slice(11,13)+ "时";
                er_w[j].innerHTML = res.hourly_forecast[j].tmp + "℃";
                er_f[j].innerHTML = res.hourly_forecast[j].wind.dir;
            }
        }
    };
    xmlhttp.open("GET","https://bird.ioliu.cn/weather?city="+ title.value,true);
    xmlhttp.send();
}
a();
title.addEventListener("change",function(){
    a();
});
let xx = document.querySelectorAll(".xx");
let zz = document.querySelectorAll(".zz");
for(var i = 0;i<xx.length;i++){
    xx[i].index = i;
    xx[i].addEventListener("click",function(){
        for(var j = 0;j<xx.length;j++){
            xx[j].classList.remove("on");
            zz[j].classList.remove("active");
        }
        this.classList.add("on");
        zz[this.index].classList.add("active");
    })
}